home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '92 / Hacks ’92 / Rotate Process / Rotate Proccess.c next >
Encoding:
C/C++ Source or Header  |  1992-06-18  |  2.0 KB  |  83 lines  |  [TEXT/KAHL]

  1. /* Rotate Process.c - © 1992 Shane D. Looker
  2.  
  3.    This is a GNE filter which will look for the Ctrl-Option right-arrow
  4.    key press. When it finds it, it will rotate to the next process in the
  5.    process list.  Wrapping is done when the end of the list is found and
  6.    faceless background apps return an error so are avoided.
  7. */
  8.  
  9. #include    <processes.h>
  10.  
  11.  
  12. pascal void main(void);
  13.  
  14. #define    kMaximumBackgroundOnlyApps    100
  15.  
  16. #undef    __DEBUG__
  17.  
  18. pascal void main(void)
  19. {
  20.     Ptr        addr;
  21.     Ptr        globalP;
  22.     long    rD0;
  23.     EventRecord    *rA1;
  24.     
  25.     asm {
  26.         MOVEM.L    A2-A5/D1-D7, -(A7)            /* Save the non-volitle registers         */
  27.         MOVE.L    d0, rD0                        /* Get to d0 & a0 easily */
  28.         MOVE.L    a1, rA1
  29.     }
  30.         
  31.     addr = *(Ptr *)(((Ptr)&main) - 8);        /* Get the address of last filter     */
  32.     globalP = *(Ptr *)(((Ptr)&main) - 4);    /* Get the address of global storage     */
  33.                                             /* The structure is:
  34.                                                     long    last filter address;
  35.                                                     Ptr        globalDataSpace;        */
  36.     if ((rA1)->what == keyDown)
  37.     {
  38.         if (((((rA1)->message & keyCodeMask) >> 8) == 0x7C) &&    /* Right arrow key */
  39.             ((rA1)->modifiers & controlKey) && ((rA1)->modifiers & optionKey))
  40.         {
  41.             ProcessSerialNumber    thePSN;
  42.             short    err;
  43.             short    attemptCount = 0;
  44.             
  45.             err = GetCurrentProcess(&thePSN);
  46. #ifdef    __DEBUG__
  47.             if (err)
  48.                 DebugStr("\PError with GetCurrentProcess");
  49. #endif
  50.         
  51.             do {
  52.                 err = GetNextProcess(&thePSN);
  53.                 if (err)
  54.                 {
  55.                     thePSN.lowLongOfPSN = kNoProcess;
  56.                     err = GetNextProcess(&thePSN);
  57. #ifdef    __DEBUG__
  58.                     if (err)
  59.                         DebugStr("\PError with GetNextProcess");
  60. #endif
  61.                 }
  62.                     
  63.                 err = SetFrontProcess(&thePSN);
  64.             } while (err && (attemptCount++ < kMaximumBackgroundOnlyApps));
  65.             
  66.             if (err == 0)
  67.                 (rA1)->what = nullEvent;        /* Kill the key event so nobody gets confused */
  68. #ifdef    __DEBUG__
  69.             else
  70.                 DebugStr("\PError with SetFrontProcess");
  71. #endif
  72.         }
  73.     }
  74.     
  75.     asm {
  76.             MOVEM.L        (A7)+, A2-A5/D1-D7    /* Restore the non-volitle registers    */
  77.             MOVE.L        rD0, d0
  78.             MOVE.L        rA1, a1
  79.             MOVE.L        addr, A0
  80.             UNLK        A6
  81.             JMP            (A0)        
  82.     };
  83. }